/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uni.j2ee.forum.model;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author Lubomir
 */
@Entity
@Table(name = "POSTS")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "ForumPost.findAll", query = "SELECT f FROM ForumPost f"),
    @NamedQuery(name = "ForumPost.findByPostId", query = "SELECT f FROM ForumPost f WHERE f.postId = :postId"),
    @NamedQuery(name = "ForumPost.findByPostDate", query = "SELECT f FROM ForumPost f WHERE f.postDate = :postDate"),
    @NamedQuery(name = "ForumPost.findByUsername", query = "SELECT f FROM ForumPost f WHERE f.username = :username"),
    @NamedQuery(name = "ForumPost.findByTopicId", query = "SELECT f FROM ForumPost f WHERE f.topicId = :topicId")
})
public class ForumPost implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "post_id")
    private Integer postId;
    @Lob
    @Size(max = 32700)
    @Column(name = "content")
    private String content;
    @Column(name = "post_date")
    @Temporal(TemporalType.DATE)
    private Date postDate;
    @JoinColumn(name = "username", referencedColumnName = "username")
    @ManyToOne
    private ForumUser username;
    @JoinColumn(name = "topic_id", referencedColumnName = "topic_id")
    @ManyToOne
    private ForumTopic topicId;

    public ForumPost() {
    }

    public ForumPost(Integer postId) {
        this.postId = postId;
    }

    public Integer getPostId() {
        return postId;
    }

    public void setPostId(Integer postId) {
        this.postId = postId;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public Date getPostDate() {
        return postDate;
    }

    public void setPostDate(Date postDate) {
        this.postDate = postDate;
    }

    public ForumUser getUsername() {
        return username;
    }

    public void setUsername(ForumUser username) {
        this.username = username;
    }

    public ForumTopic getTopicId() {
        return topicId;
    }

    public void setTopicId(ForumTopic topicId) {
        this.topicId = topicId;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (postId != null ? postId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ForumPost)) {
            return false;
        }
        ForumPost other = (ForumPost) object;
        if ((this.postId == null && other.postId != null) || (this.postId != null && !this.postId.equals(other.postId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "uni.j2ee.forum.model.ForumPost[ postId=" + postId + " ]";
    }
    
}
